/*
 * @Description:
 * @Autor: lcz
 * @Date: 2023-06-09 18:34:29
 * @LastEditors: lcz
 * @LastEditTime: 2023-07-03 17:53:12
 */
import classNames from 'classnames';
import { useWhyDidYouUpdate } from 'ahooks';
import { Tree } from 'antd';
import type { DataNode } from 'antd/es/tree';
import { Key } from 'react';
import styles from './scss/tree.module.less';
import { DownOutlined } from '@ant-design/icons';
export interface TreeContainerProps {
  treeData?: DataNode[];
  checkedKeys?: Array<string | number>;
  onCheck?: any;
  defaultExpandedKeys?: Key[];
  isCheckBox?: boolean;
  showLine?: boolean;
  defaultExpandAll?:boolean
}

const TreeComponent = (props: TreeContainerProps) => {
  // useWhyDidYouUpdate('TreeContainer', { ...props })
  const { checkedKeys, onCheck, treeData, isCheckBox, defaultExpandedKeys, showLine,defaultExpandAll } = props;

  const treeCls = classNames({ [styles.TreeReset]: !isCheckBox, 'lcz-reset-tree': true,[styles.hideFileIcon]:showLine });

  return (
    <Tree
      defaultExpandAll={defaultExpandAll}
      switcherIcon={showLine ? <DownOutlined /> : null}
      showLine={showLine}
      // rowKey="key"
      // defaultExpandParent
      className={treeCls}
      checkable
      checkStrictly={!isCheckBox}
      // defaultExpandAll
      // autoExpandParent={true} //是否自动展开父节点
      defaultExpandedKeys={defaultExpandedKeys}
      checkedKeys={checkedKeys}
      onCheck={onCheck}
      treeData={treeData}
    />
  );
};

export default TreeComponent;
